package controller;

import entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import vo.AjaxResult;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2023-09-21 10:22
 * Description：<描述>
 */
// @Controller
// @ResponseBody
@RestController // 等价于@Controller+@ResponseBody
// @CrossOrigin
public class AjaxController {

    // @ResponseBody
    @RequestMapping("/ajax1")
    public User ajax1(){
        User user = new User(1,"张三","123",18,192.4, LocalDateTime.now());
        System.out.println(user);
        return user;
    }

    // @ResponseBody
    @RequestMapping("/ajax2")
    public AjaxResult ajax2(){
        List<User> list = new ArrayList<>();
        list.add(new User(1,"张三","123",18,192.4, LocalDateTime.now()));
        list.add(new User(2,"李四","123",18,192.4, LocalDateTime.now()));
        list.add(new User(3,"王五","123",18,192.4, LocalDateTime.now()));
        return AjaxResult.success(list);
    }
}
